//对axios进行二次封装
import axios from "axios";
//导入nprogress
// import NProgress from 'nprogress'
// import 'nprogress/nprogress.css'
//引入store

const requests = axios.create({
    baseURL: '/device',
    timeout: 600000,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
    },
});

//请求拦截
requests.interceptors.request.use((config) => {
        // NProgress.start();
        // console.log(store.state.detail.uuid_token);
        // if (localStorage.getItem('uuid_token')) {
        //在请求头加入token，名字要和后端接收请求头的token名字一样
        // let token ='Bearer '+ localStorage.getItem('uuid_token').replaceAll("\"","");
        // config.headers.Authorization = token;
        // }
        return config;
    },
    error => {
        return Promise.reject(error);
    }
)
//响应拦截
requests.interceptors.response.use((res) => {
    console.log("requests", "请求结束" + res)
    // NProgress.done();
    return res.data;
// eslint-disable-next-line no-unused-vars
}), (error) => {
    console.log("requests", "请求异常" + error)
    return Promise.reject(new Error("faile"));
}

export default requests;
